<script>
import { mapMutations } from 'vuex';
import debug from '@/utils/log';
// #ifdef H5
import { wxAuthorize } from './utils/wechat';
// #endif

export default {
  methods: {
    ...mapMutations(['login', 'getAppSettings']),
  },
  onLaunch: function () {
    // 检查缓存中是否存在用户登录信息
    const token = uni.getStorageSync('token');
    const userInfo = uni.getStorageSync('userInfo');
    const expiredTime = uni.getStorageSync('expiredTime');
    if (token && userInfo && Date.now() < +expiredTime) {
      this.login({ token, userInfo, cache: false });
    } else {
      // #ifdef H5
      // 微信环境自动登录
      const ua = navigator.userAgent.toLowerCase();
      if (
        ua.match(/MicroMessenger/i) == 'micromessenger' &&
        window.location.origin === 'h5.lantingshucheng.com'
      ) {
        wxAuthorize();
      }
      // #endif
    }

    // 获取应用配置
    this.$store.dispatch('getAppSettings');
  },
  onShow: function () {},
  onHide: function () {},
  onError: function (err) {
    debug('app-onerror', 'onError', err);
  },
};
</script>

<style lang='scss'>
/*
    全局公共样式和字体图标
  */
@import url('./static/font/iconfont.css');

view,
scroll-view,
swiper,
swiper-item,
cover-view,
cover-image,
icon,
text,
rich-text,
progress,
button,
checkbox,
form,
input,
label,
radio,
slider,
switch,
textarea,
navigator,
audio,
camera,
image,
video {
  box-sizing: border-box;
}

/* 骨架屏替代方案 */
.Skeleton {
  background: #f3f3f3;
  padding: 20rpx 0;
  border-radius: 8rpx;
}

/* 图片载入替代方案 */
.image-wrapper {
  font-size: 0;
  background: #f3f3f3;
  border-radius: 4px;

  image {
    width: 100%;
    height: 100%;
    transition: 0.6s;
    opacity: 0;

    &.loaded {
      opacity: 1;
    }
  }
}

.clamp {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.common-hover {
  background: #f5f5f5;
}

/*边框*/
.b-b:after,
.b-t:after {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  height: 0;
  content: '';
  transform: scaleY(0.5);
  border-bottom: 1px solid $border-color-base;
}

.b-b:after {
  bottom: 0;
}

.b-t:after {
  top: 0;
}

/* button样式改写 */
uni-button,
button {
  height: 80rpx;
  line-height: 80rpx;
  font-size: $font-lg + 2rpx;
  font-weight: normal;

  &.no-border:before,
  &.no-border:after {
    border: 0;
  }
}

uni-button[type='default'],
button[type='default'] {
  color: $font-color-dark;
}

/* input 样式 */
.input-placeholder {
  color: #999999;
}

.placeholder {
  color: #999999;
}

.uni-input-form {
  height: 100%;
}

.booklist__search-input input {
  padding-left: 80rpx;
}
</style>
